﻿using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PugLib.Net;

namespace PugLib.UnitTest
{
    [TestClass()]
    public class LatestFileVersionDownloaderTest
    {
        [TestMethod()]
        public void EnsureLatestVersionOnDiskTest()
        {
            const string fileName = "EnsureLatestVersionOnDiskTest.test";
            Uri remoteFile = new Uri("http://www.gutenberg.org/dirs/00README.TXT");
            string localDownloadPath = Path.GetTempPath();
            Uri localFile = new Uri(Path.Combine(localDownloadPath, fileName), UriKind.Absolute);

            if (File.Exists(localFile.AbsolutePath))
            {
                File.Delete(localFile.AbsolutePath);
            }

            LatestFileVersionDownloader target = new LatestFileVersionDownloader(remoteFile, localFile);
            target.EnsureLatestVersionOnDisk();
            Assert.IsTrue(File.Exists(target.LocalFilePath));

            target = new LatestFileVersionDownloader(remoteFile, localFile);
            target.EnsureLatestVersionOnDisk();

            Assert.IsTrue(File.Exists(target.LocalFilePath));
        }
    }
}